// the functions in this file require the supplementary library lib.js

// These defaults should be changed the way it best fits your site
var _POPUP_FEATURES = '';

function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target)) target   = 'popup';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return theWindow;
}
function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}


function enlg_popup_old(src, features) {
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}
function enlg_popup(src, width, height) {
	/* if ((screen.width == 640) && (screen.height == 480)) 
window.location.href= url640x480;
else if ((screen.width == 800) && (screen.height == 600))
window.location.href= url800x600;
else if ((screen.width == 1024) && (screen.height == 768))
window.location.href= url1024x768;
else window.location.href= url640x480;
} */
	var maxwidth = screen.width - 20; 
	var maxheight = screen.height - 65; 
	// var maxwidth = 780;	
	// var maxheight = 550;
	// alert("maxwidth: " + maxwidth + "\nmaxheight: " + maxheight);
	if (width > maxwidth) { usewidth = maxwidth; 
		// alert("Maxwidth: " + maxwidth);
		}		
	else { usewidth = width; 
		// alert("Width: " + width);
		}
	if (height > maxheight) { useheight = maxheight; 
		// alert("Maxheight: " + maxheight);
		}
	else { useheight = height; 
		//alert("Height: " + height);
		}
	
	var features = "scrollbars=1,status=0,toolbar=0,menubar=0,location=0,width=" + usewidth + ",height=" + useheight + ",top=40,left=40,resizable=no";
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || 'popup', features);
}
function vt_popup(src, res) {
	vt_popup(src, 'low');
}
function vt_popup(src, res) {
	var width = 749;
	var height = 670;
	/* if ((screen.width == 640) && (screen.height == 480)) 
window.location.href= url640x480;
else if ((screen.width == 800) && (screen.height == 600))
window.location.href= url800x600;
else if ((screen.width == 1024) && (screen.height == 768))
window.location.href= url1024x768;
else window.location.href= url640x480;
} */
	var maxwidth = screen.width - 20; 
	var maxheight = screen.height - 65; 
	// var maxwidth = 780;	
	// var maxheight = 550;
	// alert("maxwidth: " + maxwidth + "\nmaxheight: " + maxheight);
	if (width > maxwidth) { usewidth = maxwidth; 
		// alert("Maxwidth: " + maxwidth);
		}		
	else { usewidth = width; 
		// alert("Width: " + width);
		}
	if (height > maxheight) { useheight = maxheight; 
		// alert("Maxheight: " + maxheight);
		}
	else { useheight = height; 
		//alert("Height: " + height);
		}
	
	var features = "scrollbars=1,status=0,toolbar=0,menubar=0,location=0,width=" + usewidth + ",height=" + useheight + ",top=40,left=40,resizable=no";
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || 'popup', features);
}


function event_popup(e) {
    // to be passed as an event listener
    // pops up a window grabbing the url from the event source's href
    link_popup(e.currentTarget);
    e.preventDefault();
}

function event_popup_features(features) {
    // generates an event listener similar to event_popup, but allowing window features
    return function(e) { link_popup(e.currentTarget, features); e.preventDefault() }
}

